/* PexifTool - $Revision$
 * Copyright (C) 2011 Petros Dolaschjan.  All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *	$Id$
 */
package de.pd.pjim2.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author petros
 *
 */
public class PJFolderChangesBean implements Comparable<PJFolderChangesBean> {

	private String dir;
	
	private String dirName;
	
	private int toRotate;
	
	private int toRename;
	
	private int toMove;
	
	private int total;
	
	private int totalImagesToChange;
	
	private List<PJImageFile> images;
	
	public PJFolderChangesBean() {
		images = new ArrayList<PJImageFile>();
	}

	public void addImage(PJImageFile pImg) {
		images.add(pImg);
		if(pImg.isDoMove()) toMove++;
		if(pImg.isDoRename()) toRename++;
		if(pImg.isDoRotate()) toRotate++;
		if(!pImg.isDoNoAction()) totalImagesToChange++; // if the image has a change, increase this variable
		total++;
	}
	
	public String getDir() {
		return dir;
	}

	public void setDir(String pDir) {
		dir = pDir;
	}

	public int getToRotate() {
		return toRotate;
	}

	public int getToRename() {
		return toRename;
	}

	public int getToMove() {
		return toMove;
	}

	public int getTotal() {
		return total;
	}

	public String getDirName() {
		return dirName;
	}

	public void setDirName(String pDirName) {
		dirName = pDirName;
	}
	
	public int getTotalImagesToChange() {
		return totalImagesToChange;
	}

	/** Returns the cumulative amount of changes on files.
	 * So eg. if one file has to be renamed and rotated, then 
	 * the figure will be 2.  
	 * 
	 */
	public int getTotalChanges() {
		return toRename + toMove + toRotate;
	}

	public List<PJImageFile> getImages() {
		Collections.sort(images);
		return images;
	}

	public void setImages(List<PJImageFile> pImages) {
		for (PJImageFile img : pImages) {
			addImage(img);
		}
	}
	
	public String getHTMLFormattedDetails() {
		StringBuffer cntText = new StringBuffer();
		cntText.append("<html><table border='0' style='font-size: 12pt' cellpadding='0' cellspacing='0'>");
		cntText.append("<tr><td width='130'><b>Total Images:</b></td><td>" + getTotal() + "</td></tr>");
		cntText.append("<tr><td><b>To Rotate:</b></td><td>" + getToRotate() + "</td></tr>");
		cntText.append("<tr><td><b>To Rename:</b></td><td>" + getToRename() + "</td></tr>");
		cntText.append("<tr><td><b>To Move:</b></td><td>" + getToMove() + "</td></tr>");
		cntText.append("</table></html>");
		return cntText.toString();
	}
	
	@Override
	public int compareTo(PJFolderChangesBean o) {
		return getDirName().compareToIgnoreCase(o.dirName);
	}
}
